﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SIGCBI.Entities;
using System.Data;
using System.Data.Entity;
using System.Data.Objects;

namespace SIGCBI.Repository
{
    public interface IMenuRepository
    {
        List<MENU> GetAllMenu();
        List<MENU> GetAllFromMenuByTag(Int32 tag);
        List<MENU> GetAllFromMenuByMantenimientoByTag(Int32 tag);
        List<MENU> GetAllFromMenuByMantenimientoByTagByReturn(Int32 tag);
    }

    public class MenuRepository : MasterDataAccess, IMenuRepository
    {
        public List<Entities.MENU> GetAllMenu()
        {
            var query = from m in Context.MENUs
                        where m.Tag == 1000 || m.Tag == 2000 || m.Tag == 3000 || m.Tag == 4000 || m.Tag == 5000 
                        select m;
            return query.ToList();
        }


        /*metodo para avanzar a las sub pestañas del menu general*/
        public List<MENU> GetAllFromMenuByTag(int tag)
        {
            if (tag == 1000)
            {
                var query = from m in Context.MENUs
                            where m.Tag == 1010 || m.Tag == 1011 || m.Tag == 1012 || m.Tag == 1020 || m.Tag == 1021 || m.Tag == 1022 || m.Tag == 1030 ||
                                      m.Tag == 1031 || m.Tag == 1040 || m.Tag == 1041 || m.Tag == 1042 || m.Tag == 1050 || m.Tag == 1051 || m.Tag == 1052 || m.Tag == 1060 ||
                                      m.Tag == 1061 
                            select m;
                return query.ToList();
            }
            else if (tag == 2000)
            {
                var query = from m in Context.MENUs
                            where m.Tag == 2010 || m.Tag == 2011 || m.Tag == 2012 || m.Tag == 2020 || m.Tag == 2021 || m.Tag == 2022 || m.Tag == 2030
                            || m.Tag == 2031 || m.Tag == 2032 || m.Tag == 2040 || m.Tag == 2041 || m.Tag == 2042 || m.Tag == 2050 || m.Tag == 2051 || m.Tag == 2052 || m.Tag == 2060
                            || m.Tag == 2061 || m.Tag == 2062 || m.Tag == 2070 || m.Tag == 2071 || m.Tag == 2072
                            select m;
                return query.ToList();
            }
            else if (tag == 3000)
            {
                var query = from m in Context.MENUs
                            where m.Tag == 3010 || m.Tag == 3011 || m.Tag == 3012 || m.Tag == 3020 || m.Tag == 3021 || m.Tag == 3022
                            select m;
                return query.ToList();
            }
            else
            {
                var query = from m in Context.MENUs
                            where m.Tag == null
                            select m;
                return query.ToList();
            }
        }


        /*metodo para avanzar a los detalles de cada pestaña del menu*/
        public List<MENU> GetAllFromMenuByMantenimientoByTag(int tag)
        {
            if (tag == 1010)
            {
                var query = from m in Context.MENUs
                            where m.Tag == 1011 || m.Tag == 1012
                            select m;
                return query.ToList();
            }
            else if (tag == 1020)
            {
                var query = from m in Context.MENUs
                            where m.Tag == 1021 || m.Tag == 1022                            
                            select m;
                return query.ToList();
            }
            else if (tag == 1030)
            {
                var query = from m in Context.MENUs
                            where m.Tag == 1031
                            select m;
                return query.ToList();
            }
            else if (tag == 1040)
            {
                var query = from m in Context.MENUs
                            where m.Tag == 1041 || m.Tag == 1042
                            select m;
                return query.ToList();
            }
            else if (tag == 1050)
            {
                var query = from m in Context.MENUs
                            where m.Tag == 1051 || m.Tag == 1052
                            select m;
                return query.ToList();
            }
            else if (tag == 1060)
            {
                var query = from m in Context.MENUs
                            where m.Tag == 1061
                            select m;
                return query.ToList();
            }
            else if (tag == 2010)
            {
                var query = from m in Context.MENUs
                            where m.Tag == 2011 || m.Tag == 2012                           
                            select m;
                return query.ToList();
            }
            else if (tag == 2020)
            {
                var query = from m in Context.MENUs
                            where m.Tag == 2021 || m.Tag == 2022
                            select m;
                return query.ToList();
            }
            else if (tag == 2030)
            {
                var query = from m in Context.MENUs
                            where m.Tag == 2031 || m.Tag == 2032 
                            select m;
                return query.ToList();
            }
            else if (tag == 2040)
            {
                var query = from m in Context.MENUs
                            where m.Tag == 2041 || m.Tag == 2042 
                            select m;
                return query.ToList();
            }
            else if (tag == 2050)
            {
                var query = from m in Context.MENUs
                            where m.Tag == 2051 || m.Tag == 2052 
                            select m;
                return query.ToList();
            }
            else if (tag == 2060)
            {
                var query = from m in Context.MENUs
                            where m.Tag == 2061 || m.Tag == 2062
                            select m;
                return query.ToList();
            }
            else if (tag == 2070)
            {
                var query = from m in Context.MENUs
                            where m.Tag == 2071 || m.Tag == 2072
                            select m;
                return query.ToList();
            }
            else if (tag == 3010)
            {
                var query = from m in Context.MENUs
                            where m.Tag == 3011 || m.Tag == 3012
                            select m;
                return query.ToList();
            }
            else if (tag == 3020)
            {
                var query = from m in Context.MENUs
                            where m.Tag == 3021 || m.Tag == 3022
                            select m;
                return query.ToList();
            }
           
            else
            {
                var query = from m in Context.MENUs
                            where m.Tag == null
                            select m;
                return query.ToList();
            }
        }


        /*metodo para retroceder en la buskeda del menu*/
        public List<MENU> GetAllFromMenuByMantenimientoByTagByReturn(int tag)
        {
            ////if(tag >= 1010 && tag <= 3022)
            //////if (tag == 1011 || tag == 1012 || tag == 1021 || tag == 1022 || tag == 1031 || tag == 1041 || tag == 1042 || tag == 1051 ||
            //////   tag == 1052 || tag == 1061 || tag == 2011 || tag == 2012 || tag == 2021 || tag == 2022 || tag == 2031 || tag == 2032 ||
            //////   tag == 2041 || tag == 2042 || tag == 2051 || tag == 2052 || tag == 2061 || tag == 2062 || tag == 2071 || tag == 2072 ||
            //////   tag == 3011 || tag == 3012 || tag == 3021 || tag == 3022)
            ////{
            ////    var query = from m in Context.MENUs
            ////                where m.Tag == 1010 || m.Tag == 1020 || m.Tag == 1030 || m.Tag == 1040 || m.Tag == 1050 || m.Tag == 1060 || m.Tag == 2010 || m.Tag == 2020 ||
            ////                          m.Tag == 2030 || m.Tag == 2040 || m.Tag == 2050 || m.Tag == 2060 || m.Tag == 2070 || m.Tag == 3010 || m.Tag == 3020 
            ////                select m;
            ////    return query.ToList();
            ////}

            ////else
            //    if (tag >= 1011 && tag <= 1061)
            //    //if (tag == 1011 || tag == 1012 || tag == 1021 || tag == 1022 || tag == 1031 || tag == 1041 || tag == 1042 || tag == 1051 ||
            ////             tag == 1052 || tag == 1061)         
            //{
            //    var query = from m in Context.MENUs
            //                where m.Tag == 1010 || m.Tag == 1020 || m.Tag == 1030 || m.Tag == 1040 || m.Tag == 1050
            //                    || m.Tag == 1060
            //                select m;
            //    return query.ToList();
            //}

            //else 
            //        if(tag >= 2011 && tag <= 2072)
            //        //if (tag == 2011 || tag == 2012 || tag == 2021 || tag == 2022 || tag == 2031 || tag == 2032 ||
            ////         tag == 2041 || tag == 2042 || tag == 2051 || tag == 2052 || tag == 2061 || tag == 2062 || tag == 2071 || tag == 2072)
            //{
            //    var query = from m in Context.MENUs
            //                where m.Tag == 2010 || m.Tag == 2020 || m.Tag == 2030 || m.Tag == 2040 || m.Tag == 2050 || m.Tag == 2060 || m.Tag == 2070
            //                select m;
            //    return query.ToList();
            //}

            //else if(tag <= 3011 && tag >= 3022)
            //            //if (tag == 3011 || tag == 3012 || tag == 3021 || tag == 3022)
            //{
            //    var query = from m in Context.MENUs
            //                where m.Tag == 3010 || m.Tag == 3020
            //                select m;
            //    return query.ToList();
            //}
            if (tag != 1000 || tag != 2000 || tag != 3000 || tag != 4000 || tag != 5000)
            {
                var query = from m in Context.MENUs
                            where m.Tag == 1000 || m.Tag == 2000 || m.Tag == 3000 || m.Tag == 4000 || m.Tag == 5000
                            select m;
                return query.ToList();
            }
            else
            {
                var query = from m in Context.MENUs
                            where m.Tag == null
                            select m;
                return query.ToList();
            }
        }
    }
}